<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RocketMQ 核心组件深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            overflow-x: auto;
            position: relative;
        }
        
        .code-block::before {
            content: 'Java';
            position: absolute;
            top: 8px;
            right: 12px;
            font-size: 12px;
            color: #666;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
        
        .feature-card {
            background: linear-gradient(135deg, #f5f7fa 0%, #e9ecef 100%);
            border-left: 4px solid #667eea;
            transition: all 0.3s ease;
        }
        
        .feature-card:hover {
            transform: translateX(4px);
            box-shadow: 0 10px 20px rgba(102, 126, 234, 0.1);
        }
        
        .mermaid {
            background: transparent;
            padding: 20px;
        }
        
        .drop-cap {
            float: left;
            font-size: 3.5em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
            border-left: 3px solid #667eea;
            padding: 16px 20px;
            margin: 20px 0;
            border-radius: 0 8px 8px 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-8">
        <div class="max-w-6xl mx-auto animate-fade-in">
            <h1 class="text-5xl font-bold mb-6 tracking-tight">
                <i class="fas fa-rocket mr-4"></i>RocketMQ 核心组件深度解析
            </h1>
            <p class="text-xl opacity-90 leading-relaxed max-w-3xl">
                深入探索 Apache RocketMQ 的架构精髓，从 NameServer 的服务发现到 Broker 的存储设计，
                再到 Producer 的发送机制，全方位解析分布式消息中间件的技术内核。
            </p>
            <div class="mt-8 flex items-center space-x-6 text-sm opacity-80">
                <span><i class="far fa-clock mr-2"></i>阅读时间：约 25 分钟</span>
                <span><i class="far fa-bookmark mr-2"></i>技术深度：高级</span>
                <span><i class="far fa-lightbulb mr-2"></i>实战价值：极高</span>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-8 py-12">
        <!-- Architecture Overview -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-12">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-sitemap mr-3 text-purple-600"></i>架构概览
            </h2>
            <div class="prose prose-lg max-w-none">
                <p class="text-gray-700 leading-relaxed">
                    <span class="drop-cap">R</span>ocketMQ 作为阿里巴巴开源的分布式消息中间件，其架构设计充分体现了高可用、高性能、可扩展的特点。
                    整个系统由四大核心组件构成：NameServer（命名服务）、Broker（消息代理）、Producer（生产者）和 Consumer（消费者）。
                    每个组件都有其独特的职责和精妙的设计，共同构建了一个强大的消息传递系统。
                </p>
            </div>
            
            <!-- Architecture Diagram -->
            <div class="mt-8 bg-gray-50 rounded-lg p-6">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-project-diagram mr-2 text-purple-600"></i>系统架构图
                </h3>
                <div class="mermaid">
                    graph TB
                        subgraph "NameServer Cluster"
                            NS1[NameServer 1]
                            NS2[NameServer 2]
                            NS3[NameServer N]
                        end
                        
                        subgraph "Broker Cluster"
                            subgraph "Broker Group 1"
                                B1M[Broker 1 Master]
                                B1S[Broker 1 Slave]
                            end
                            subgraph "Broker Group 2"
                                B2M[Broker 2 Master]
                                B2S[Broker 2 Slave]
                            end
                        end
                        
                        subgraph "Client"
                            P1[Producer 1]
                            P2[Producer 2]
                            C1[Consumer 1]
                            C2[Consumer 2]
                        end
                        
                        P1 -.->|路由查询| NS1
                        P2 -.->|路由查询| NS2
                        C1 -.->|路由查询| NS3
                        C2 -.->|路由查询| NS1
                        
                        B1M -->|心跳注册| NS1
                        B1M -->|心跳注册| NS2
                        B1M -->|心跳注册| NS3
                        B2M -->|心跳注册| NS1
                        B2M -->|心跳注册| NS2
                        B2M -->|心跳注册| NS3
                        
                        P1 -->|发送消息| B1M
                        P2 -->|发送消息| B2M
                        C1 -->|拉取消息| B1M
                        C2 -->|拉取消息| B2M
                        
                        B1M -->|主从同步| B1S
                        B2M -->|主从同步| B2S
                        
                        style NS1 fill:#e1bee7,stroke:#7b1fa2
                        style NS2 fill:#e1bee7,stroke:#7b1fa2
                        style NS3 fill:#e1bee7,stroke:#7b1fa2
                        style B1M fill:#c5e1a5,stroke:#558b2f
                        style B2M fill:#c5e1a5,stroke:#558b2f
                        style B1S fill:#dcedc8,stroke:#689f38
                        style B2S fill:#dcedc8,stroke:#689f38
                        style P1 fill:#ffccbc,stroke:#d84315
                        style P2 fill:#ffccbc,stroke:#d84315
                        style C1 fill:#b3e5fc,stroke:#0277bd
                        style C2 fill:#b3e5fc,stroke:#0277bd
                </div>
            </div>
        </div>

        <!-- NameServer Section -->
        <div class="content-card rounded-xl shadow-xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                1. NameServer 工作原理
            </h2>
            
            <!-- Architecture Design -->
            <div class="mb-10">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-cube mr-2 text-purple-600"></i>架构设计与功能职责
                </h3>
                <p class="text-gray-700 leading-relaxed mb-6">
                    NameServer 是 RocketMQ 的核心组件之一，它充当着服务发现和路由的角色。在 RocketMQ 的架构中，
                    NameServer 提供轻量级的服务注册与发现功能，允许生产者和消费者找到相应的 Broker。
                </p>
                
                <!-- Core Functions -->
                <div class="grid grid-cols-1 md:grid-cols-2 gap-4 mb-6">
                    <div class="feature-card p-4 rounded-lg">
                        <h4 class="font-semibold text-lg mb-2">
                            <i class="fas fa-route mr-2 text-purple-600"></i>路由注册
                        </h4>
                        <p class="text-gray-600">Broker 启动后向所有 NameServer 注册，提供 Topic 路由信息</p>
                    </div>
                    <div class="feature-card p-4 rounded-lg">
                        <h4 class="font-semibold text-lg mb-2">
                            <i class="fas fa-search-location mr-2 text-purple-600"></i>路由发现
                        </h4>
                        <p class="text-gray-600">生产者和消费者通过 NameServer 获取 Topic 的路由信息</p>
                    </div>
                    <div class="feature-card p-4 rounded-lg">
                        <h4 class="font-semibold text-lg mb-2">
                            <i class="fas fa-trash-alt mr-2 text-purple-600"></i>路由删除
                        </h4>
                        <p class="text-gray-600">检测 Broker 存活状态，移除不可用的 Broker</p>
                    </div>
                    <div class="feature-card p-4 rounded-lg">
                        <h4 class="font-semibold text-lg mb-2">
                            <i class="fas fa-database mr-2 text-purple-600"></i>无状态设计
                        </h4>
                        <p class="text-gray-600">每个 NameServer 节点独立工作，不相互通信</p>
                    </div>
                </div>
                
                <!-- Architecture Features -->
                <div class="highlight-box">
                    <h4 class="font-semibold text-lg mb-3">
                        <i class="fas fa-star mr-2"></i>架构特点
                    </h4>
                    <ul class="space-y-2 text-gray-700">
                        <li><i class="fas fa-check-circle mr-2 text-green-600"></i><strong>简单高效：</strong>NameServer 采用了极简设计，没有复杂的状态同步机制</li>
                        <li><i class="fas fa-check-circle mr-2 text-green-600"></i><strong>内存存储：</strong>所有路由信息存储在内存中，提供快速的读写操作</li>
                        <li><i class="fas fa-check-circle mr-2 text-green-600"></i><strong>定时扫描：</strong>每 10 秒扫描一次 Broker，移除不活跃的 Broker</li>
                        <li><i class="fas fa-check-circle mr-2 text-green-600"></i><strong>水平扩展：</strong>可部署多个 NameServer 节点，提高可用性</li>
                    </ul>
                </div>
            </div>
            
            <!-- Route Registration and Discovery -->
            <div class="mb-10">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-network-wired mr-2 text-purple-600"></i>路由注册与发现机制
                </h3>
                
                <!-- Registration Flow -->
                <div class="bg-gray-50 rounded-lg p-6 mb-6">
                    <h4 class="font-semibold text-lg mb-3">路由注册流程</h4>
                    <div class="space-y-3">
                        